package com.itheima.reggie.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.itheima.reggie.common.EmployeeHolder;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
	//插入时填充
	@Override
	public void insertFill(MetaObject metaObject) {
		// createTime
		metaObject.setValue("createTime",new Date());
		metaObject.setValue("updateTime",new Date());
		metaObject.setValue("createUser", EmployeeHolder.get().getId());
		metaObject.setValue("updateUser", EmployeeHolder.get().getId());
	}
	
	
	//更新时填充
	@Override
	public void updateFill(MetaObject metaObject) {
		metaObject.setValue("updateTime", new Date());
		metaObject.setValue("updateUser", EmployeeHolder.get().getId());
	}
}
